package czk.concrent.threadpool.method.practice;

import java.util.Arrays;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * invokeAny
 * @Author:ChenZhangKun
 * @Date: 2021/1/25 22:59
 */
public class InvokeAnyDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService threadPool = Executors.newFixedThreadPool(2);
        Object o = threadPool.invokeAny(Arrays.asList(
                () -> {
                    System.out.println(1);
                    return 1;
                },
                () -> {
                    System.out.println(2);
                    return 2;
                }
        ));
        // 返回执行的return
        System.out.println(o);
    }
}
